package com.imachen.system.controller;

import com.imachen.basic.utils.AjaxResult;
import com.imachen.basic.utils.PageList;
import com.imachen.system.domain.DictionaryDetail;
import com.imachen.system.query.DictionaryDetailQuery;
import com.imachen.system.service.IDictionaryDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description: 数据字典明细接口类
 * @author: AChen
 * @date: 2022/8/14 0014 : 19:23
 * @version: ver1.0
 * @email
 */
@Api(value = "数据字典明细接口类",description = "数据字典明细接口类")
@RestController
@RequestMapping("/dictionaryDetail")
public class DictionaryDetailController {
    @Autowired
    private IDictionaryDetailService dictionaryDetailService;

    /**
     * @description: 查询所有
     * @author: AChen
     * @date: 2022/8/14 0014 : 19:23
     * @param:
     * @return:
     */
    @ApiOperation(value = "查询所有明细信息")
    @GetMapping
    public List<DictionaryDetail> finAll(){
        return dictionaryDetailService.findAll();
    }

    /**
     * @description: 查询明细单条数据
     * @author: AChen
     * @date: 2022/8/14 0014 : 19:27
     * @param:
     * @return:
     */
    @ApiOperation(value = "查询明细单条数据")
    @GetMapping("{id}")
    public DictionaryDetail finOne(@PathVariable("id")Long id){
        return dictionaryDetailService.findOneById(id);
    }

    /**
     * @description: 删除明细信息
     * @author: AChen
     * @date: 2022/8/14 0014 : 19:29
     * @param:
     * @return:
     */
    @ApiOperation(value = "删除明细信息")
    @DeleteMapping("{id}")
    public AjaxResult delete(@PathVariable("id")Long id){
        try {
            dictionaryDetailService.delete(id);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"删除失败");
        }
    }

    /**
     * @description: 添加或修改明细信息
     * @author: AChen
     * @date: 2022/8/14 0014 : 19:31
     * @param:
     * @return:
     */
    @ApiOperation(value = "添加或修改明细信息")
    @PutMapping
    public AjaxResult add0rUpt(@RequestBody DictionaryDetail DictionaryDetail){
        try {
            if (DictionaryDetail.getId() == null){
                dictionaryDetailService.add(DictionaryDetail);
            }else {
                dictionaryDetailService.update(DictionaryDetail);
            }
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"操作失败");
        }
    }

    /**
     * @description: 分页查询明细信息
     * @author: AChen
     * @date: 2022/8/14 0014 : 19:34
     * @param:
     * @return:
     */
    @ApiOperation(value = "分页查询明细信息")
    @PostMapping
    public PageList<DictionaryDetail> queryPage(@RequestBody DictionaryDetailQuery DictionaryDetailQuery){
        return dictionaryDetailService.queryPage(DictionaryDetailQuery);
    }

    /**
     * @description: 批量删除
     * @author: AChen
     * @date: 2022/8/16 0016 : 16:51
     * @param:
     * @return:
     */
    @ApiOperation(value = "批量删除")
    @PatchMapping
    public AjaxResult patchDelete(@RequestBody List<Long> ids){
        try {
            dictionaryDetailService.patchDelete(ids);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"批量删除失败");
        }
    }
}
